package com.hospital.workstation.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.hospital.workstation.domain.vo.CareLevelTriggerItemVo;
import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.hospital.common.annotation.RepeatSubmit;
import com.hospital.common.annotation.Log;
import com.hospital.common.core.controller.BaseController;
import com.hospital.common.core.domain.PageQuery;
import com.hospital.common.core.domain.R;
import com.hospital.common.core.validate.AddGroup;
import com.hospital.common.core.validate.EditGroup;
import com.hospital.common.core.validate.QueryGroup;
import com.hospital.common.enums.BusinessType;
import com.hospital.common.utils.poi.ExcelUtil;
import com.hospital.workstation.domain.vo.GradingFirstVo;
import com.hospital.workstation.domain.bo.GradingFirstBo;
import com.hospital.workstation.service.IGradingFirstService;
import com.hospital.common.core.page.TableDataInfo;

/**
 * 医学一级监护分级信息
 *
 * @author whb
 * @date 2023-05-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/workstation/gradingFirst")
public class GradingFirstController extends BaseController {

    private final IGradingFirstService iGradingFirstService;

    /**
     * 获取医学一级监护分级信息详细信息
     *
     * @param medicalRecordNo 病历号
     */
    // @SaCheckPermission("workstation:gradingFirst:query")
    @GetMapping("/{medicalRecordNo}")
    public R<GradingFirstVo> getInfo(@NotNull(message = "病历号不能为空") @PathVariable Integer medicalRecordNo) {
        return R.ok(iGradingFirstService.queryByMedicalRecordNo(medicalRecordNo));
    }

    /**
     * 更新一级分级信息和患者监护分级
     */
    // @SaCheckPermission("workstation:gradingFirst:edit")
    @Log(title = "更新医学一级监护分级信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody GradingFirstBo bo) {
        return toAjax(iGradingFirstService.insertOrUpdateByBo(bo));
    }

    /**
     * 获取监护标红项
     *
     * @param medicalRecordNo 病历号
     * @return
     */
    @GetMapping("/red/{medicalRecordNo}")
    public R<CareLevelTriggerItemVo> queryRedItem(@NotNull(message = "病历号不能为空") @PathVariable Integer medicalRecordNo) {
        return iGradingFirstService.getRedItemVo(medicalRecordNo);
    }
}
